from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-28 14:02:17.431557
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 28, May, 2022
Time: 14:02:22
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.4474
Nobs: 670.000 HQIC: -49.8183
Log likelihood: 8301.50 FPE: 1.82952e-22
AIC: -50.0528 Det(Omega_mle): 1.60114e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.304559 0.059686 5.103 0.000
L1.Burgenland 0.107886 0.038621 2.793 0.005
L1.Kärnten -0.109882 0.020298 -5.413 0.000
L1.Niederösterreich 0.197061 0.080315 2.454 0.014
L1.Oberösterreich 0.128595 0.079516 1.617 0.106
L1.Salzburg 0.255366 0.041066 6.218 0.000
L1.Steiermark 0.045773 0.053801 0.851 0.395
L1.Tirol 0.104668 0.043570 2.402 0.016
L1.Vorarlberg -0.062082 0.038462 -1.614 0.107
L1.Wien 0.032684 0.070399 0.464 0.642
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.038790 0.126883 0.306 0.760
L1.Burgenland -0.029477 0.082102 -0.359 0.720
L1.Kärnten 0.040321 0.043150 0.934 0.350
L1.Niederösterreich -0.182615 0.170738 -1.070 0.285
L1.Oberösterreich 0.447406 0.169040 2.647 0.008
L1.Salzburg 0.284345 0.087301 3.257 0.001
L1.Steiermark 0.109220 0.114373 0.955 0.340
L1.Tirol 0.314725 0.092623 3.398 0.001
L1.Vorarlberg 0.022284 0.081765 0.273 0.785
L1.Wien -0.037420 0.149658 -0.250 0.803
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.184844 0.030614 6.038 0.000
L1.Burgenland 0.089836 0.019809 4.535 0.000
L1.Kärnten -0.007828 0.010411 -0.752 0.452
L1.Niederösterreich 0.257495 0.041195 6.251 0.000
L1.Oberösterreich 0.154651 0.040786 3.792 0.000
L1.Salzburg 0.043122 0.021064 2.047 0.041
L1.Steiermark 0.024136 0.027596 0.875 0.382
L1.Tirol 0.085271 0.022348 3.816 0.000
L1.Vorarlberg 0.052601 0.019728 2.666 0.008
L1.Wien 0.116921 0.036109 3.238 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107980 0.030704 3.517 0.000
L1.Burgenland 0.045872 0.019868 2.309 0.021
L1.Kärnten -0.014092 0.010442 -1.350 0.177
L1.Niederösterreich 0.183706 0.041316 4.446 0.000
L1.Oberösterreich 0.327978 0.040905 8.018 0.000
L1.Salzburg 0.101449 0.021126 4.802 0.000
L1.Steiermark 0.109857 0.027677 3.969 0.000
L1.Tirol 0.097445 0.022414 4.348 0.000
L1.Vorarlberg 0.060499 0.019786 3.058 0.002
L1.Wien -0.021767 0.036215 -0.601 0.548
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.116308 0.057046 2.039 0.041
L1.Burgenland -0.044466 0.036913 -1.205 0.228
L1.Kärnten -0.046093 0.019400 -2.376 0.018
L1.Niederösterreich 0.141495 0.076763 1.843 0.065
L1.Oberösterreich 0.162914 0.075999 2.144 0.032
L1.Salzburg 0.281396 0.039250 7.169 0.000
L1.Steiermark 0.054712 0.051421 1.064 0.287
L1.Tirol 0.164835 0.041643 3.958 0.000
L1.Vorarlberg 0.095143 0.036761 2.588 0.010
L1.Wien 0.075970 0.067285 1.129 0.259
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.057276 0.045071 1.271 0.204
L1.Burgenland 0.032317 0.029164 1.108 0.268
L1.Kärnten 0.051593 0.015328 3.366 0.001
L1.Niederösterreich 0.204716 0.060649 3.375 0.001
L1.Oberösterreich 0.318680 0.060046 5.307 0.000
L1.Salzburg 0.040937 0.031011 1.320 0.187
L1.Steiermark 0.009425 0.040627 0.232 0.817
L1.Tirol 0.132159 0.032901 4.017 0.000
L1.Vorarlberg 0.066433 0.029044 2.287 0.022
L1.Wien 0.087015 0.053161 1.637 0.102
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.167314 0.053887 3.105 0.002
L1.Burgenland 0.008246 0.034868 0.236 0.813
L1.Kärnten -0.064868 0.018326 -3.540 0.000
L1.Niederösterreich -0.089425 0.072512 -1.233 0.217
L1.Oberösterreich 0.202761 0.071791 2.824 0.005
L1.Salzburg 0.054219 0.037076 1.462 0.144
L1.Steiermark 0.240118 0.048574 4.943 0.000
L1.Tirol 0.502283 0.039337 12.769 0.000
L1.Vorarlberg 0.059128 0.034725 1.703 0.089
L1.Wien -0.077717 0.063559 -1.223 0.221
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.150093 0.059974 2.503 0.012
L1.Burgenland 0.002833 0.038807 0.073 0.942
L1.Kärnten 0.060640 0.020396 2.973 0.003
L1.Niederösterreich 0.185937 0.080703 2.304 0.021
L1.Oberösterreich -0.060442 0.079901 -0.756 0.449
L1.Salzburg 0.206750 0.041265 5.010 0.000
L1.Steiermark 0.133709 0.054061 2.473 0.013
L1.Tirol 0.070670 0.043781 1.614 0.106
L1.Vorarlberg 0.143321 0.038648 3.708 0.000
L1.Wien 0.108219 0.070740 1.530 0.126
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.373308 0.035354 10.559 0.000
L1.Burgenland -0.000313 0.022876 -0.014 0.989
L1.Kärnten -0.021927 0.012023 -1.824 0.068
L1.Niederösterreich 0.215536 0.047573 4.531 0.000
L1.Oberösterreich 0.226981 0.047100 4.819 0.000
L1.Salzburg 0.039367 0.024325 1.618 0.106
L1.Steiermark -0.015022 0.031868 -0.471 0.637
L1.Tirol 0.095997 0.025808 3.720 0.000
L1.Vorarlberg 0.054098 0.022782 2.375 0.018
L1.Wien 0.033649 0.041700 0.807 0.420
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.038087 0.120192 0.177240 0.144405 0.103947 0.087036 0.040257 0.213393
Kärnten 0.038087 1.000000 -0.019116 0.135302 0.052725 0.091264 0.441575 -0.059558 0.094011
Niederösterreich 0.120192 -0.019116 1.000000 0.323832 0.131753 0.283637 0.077853 0.163790 0.301934
Oberösterreich 0.177240 0.135302 0.323832 1.000000 0.220948 0.311238 0.170589 0.152298 0.253329
Salzburg 0.144405 0.052725 0.131753 0.220948 1.000000 0.131342 0.100204 0.116222 0.131481
Steiermark 0.103947 0.091264 0.283637 0.311238 0.131342 1.000000 0.142670 0.120951 0.054524
Tirol 0.087036 0.441575 0.077853 0.170589 0.100204 0.142670 1.000000 0.074344 0.151026
Vorarlberg 0.040257 -0.059558 0.163790 0.152298 0.116222 0.120951 0.074344 1.000000 0.010185
Wien 0.213393 0.094011 0.301934 0.253329 0.131481 0.054524 0.151026 0.010185 1.000000